using MediatR;
using RBAC.ErrorCode;
using System.ComponentModel.DataAnnotations;

namespace RBAC.Write.Api.Application.Command.ERP.SalesManagement.Billing
{
    /// <summary>
    /// 创建开票通知单命令
    /// </summary>
    public class CreateBillingNoticeCommand : IRequest<APIResult<int>>
    {
        /// <summary>
        /// 单据编号
        /// </summary>
        public string? BillNumber { get; set; }

        /// <summary>
        /// 业务类型
        /// </summary>
        [Required(ErrorMessage = "业务类型不能为空")]
        public string BusinessType { get; set; } = string.Empty;

        /// <summary>
        /// 客户名称
        /// </summary>
        [Required(ErrorMessage = "客户名称不能为空")]
        public string CustomerName { get; set; } = string.Empty;

        /// <summary>
        /// 开户行
        /// </summary>
        public string? BankName { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        public string? AccountNumber { get; set; }

        /// <summary>
        /// 税号
        /// </summary>
        public string? TaxNumber { get; set; }

        /// <summary>
        /// 地址电话
        /// </summary>
        public string? AddressPhone { get; set; }

        /// <summary>
        /// 交付邮箱
        /// </summary>
        public string? DeliveryEmail { get; set; }

        /// <summary>
        /// 单据日期
        /// </summary>
        public DateTime? BillDate { get; set; }

        /// <summary>
        /// 操作员
        /// </summary>
        public string? Operator { get; set; }

        /// <summary>
        /// 蓝单红字
        /// </summary>
        public string? InvoiceType { get; set; }

        /// <summary>
        /// 红字原因
        /// </summary>
        public string? RedReason { get; set; }

        /// <summary>
        /// 备注信息
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 单据状态（0-开立，1-审核，2-退回）
        /// </summary>
        public int Status { get; set; } = 0;

        /// <summary>
        /// 业务状态（正常/异常）
        /// </summary>
        public string? BusinessStatus { get; set; } = "正常";

        /// <summary>
        /// 开票物料明细列表
        /// </summary>
        public List<CreateBillingMaterialDto> Items { get; set; } = new List<CreateBillingMaterialDto>();
    }

    /// <summary>
    /// 创建开票物料明细DTO
    /// </summary>
    public class CreateBillingMaterialDto
    {
        /// <summary>
        /// 销售订单号
        /// </summary>
        public string? OrderNumber { get; set; }

        /// <summary>
        /// 物料编码
        /// </summary>
        public string? MaterialCode { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string? MaterialName { get; set; }



        /// <summary>
        /// 主计量单位
        /// </summary>
        public string? Unit { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        [Range(0, int.MaxValue, ErrorMessage = "数量必须大于等于0")]
        public int? Quantity { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        [Range(0, double.MaxValue, ErrorMessage = "单价必须大于等于0")]
        public decimal? UnitPrice { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public decimal? Amount { get; set; }

        /// <summary>
        /// 开票名称
        /// </summary>
        public string? InvoiceName { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }
    }
}